package dao;
import java.util.List;

import org.hibernate.Transaction;
import org.hibernate.classic.Session;

import util.HibernateUtil;
import entity.Marca;
import entity.TipoProduto;

public class MarcaDaoImplementation implements MarcaDao {

	public void save(Marca marca) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.save(marca);
		transaction.commit();
		session.close();
	}

	public void update(Marca marca) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.update(marca);
		transaction.commit();
	}

	public void delete(Marca marca) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		session.delete(marca);
		transaction.commit();
	}

	public void consult(Marca marca) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = session.beginTransaction();
		marca = (Marca) session.load(Marca.class, new String("Marca"));
	}

	public Marca getMarca(long id) 
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		return (Marca) session.load(Marca.class, id);
	}
	
	public List<Marca> list() 
	{
	Session session = HibernateUtil.getSessionFactory().openSession();
	Transaction transaction = session.beginTransaction();
	String sql = "SELECT new Marca( m.idMarca, m.descricao) FROM Marca m";
	List<Marca> lista = session.createQuery(sql).list();
	transaction.commit();
	session.close();
	return lista;
	}
	

}
